package rt

import "fmt"

type Limit interface {
	LimitSQL() string
}

type limit struct {
	limit int
}

func (l *limit) LimitSQL() string {
	return fmt.Sprintf(" limit %d", l.limit)
}

// NewLimit  limit ${limitCount}
func NewLimit(limitCount int) Limit {
	return &limit{limit: limitCount}
}

type limitOffset struct {
	limit  int
	offset int
}

func (l *limitOffset) LimitSQL() string {
	return fmt.Sprintf(" limit %d offset %d", l.limit, l.offset)
}

// NewLimitOffset limit ${limit} offset ${offset}
func NewLimitOffset(limit, offset int) Limit {
	return &limitOffset{limit: limit, offset: offset}
}

type limitFrom struct {
	from  int
	limit int
}

func (l *limitFrom) LimitSQL() string {
	return fmt.Sprintf(" limit %d,%d", l.from, l.limit)
}

// NewLimit  limit ${from},${limit}
func NewLimitFrom(from, limit int) Limit {
	return &limitFrom{from: from, limit: limit}
}
